package com.season.act;

import com.season.dto.StudentDTO;
import org.activiti.engine.*;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;

public class StuService {

    private ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
    //add
    public  void add(){
        RepositoryService repositoryService = processEngine.getRepositoryService();
        Deployment deploy = repositoryService.createDeployment()
                .addClasspathResource("qj4.bpmn")
                .name("请假")
                .deploy();
        System.out.println("部署ID"+deploy.getId());
    }
    //start:学员登录系统，开始请假,首先启动请假流程
    public void start(){
        RuntimeService runtimeService = processEngine.getRuntimeService();
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("stuProcess");
        System.out.println(processInstance.getProcessDefinitionId());
    }
    public void stuComplete(){
        TaskService taskService = processEngine.getTaskService();
        String taskid="20004";
        taskService.setVariable(taskid,"days",3);
        taskService.setVariable(taskid,"reson","fentouzhangcao");
        StudentDTO dto=new StudentDTO(1,"lalala");
        taskService.setVariable(taskid,"stu",dto);
        taskService.complete(taskid);
    }
    public void teaCom(){
        TaskService taskService = processEngine.getTaskService();
        String taskId = "22507";
        //得到请假原因
        Integer days = (Integer) taskService.getVariable(taskId, "days");
        System.out.println("请假天数"+days);
        String reson = (String)taskService.getVariable(taskId, "reson");
        System.out.println("请假原因"+reson);
        StudentDTO stu = (StudentDTO)taskService.getVariable(taskId, "stu");
        //学员信息
        System.out.println(stu.getStuID()+"\t"+stu.getStuName());
        taskService.complete(taskId);
    }


    public static void main(String[] args) {
        StuService stuService=new StuService();
        //stuService.add();
        //stuService.start();
        //stuService.stuComplete();
        stuService.teaCom();
    }
}
